from random import random


#接收每个队能力值,比赛场次数
def getNengli():
    numA = eval(input("请输入甲队的实力值(0-1)为:"))
    numB = eval(input("请输入乙队的实力值(0-1)为:"))
    chang = eval(input("请输入模拟比赛的场次:"))
    return numA,numB,chang

#设定每局比赛的规则
def setBiSai(ju,sumA,sumB):
    if ju<=4:
        return (sumA>=25 and abs(sumA-sumB)>2) or (sumB>=25 and abs(sumA-sumB)>2)
    else:
        return (sumA>=15 and abs(sumA-sumB)>=2) or (sumB>=15 and abs(sumA-sumB)>=2)

#模拟一场比赛
def oneBiSai(chang,numA,numB):
    sumA,sumB=0,0
    sery='A'
    while not setBiSai(chang,sumA,sumB):
        if sery=='A':
            if random()> numA:
                sumB+=1
                sery='B'
            else:
                sumA+=1
        if sery=='B':
            if random()> numB:
                sumA+=1
                sery='A'
            else:
                sumB+=1
    print("甲队第{}场获取分数为: {}".format(chang,sumA))
    print("乙队第{}场获取分数为: {}".format(chang,sumB))
    return sumA,sumB


#模拟一局比赛
def oneJu(numA,numB):
    one=1
    winJa,winYi=0,0
    for _ in range(5):
        sumA,sumB =oneBiSai(one,numA,numB)
        if(sumA > sumB):
            winJa+=1
        else:
            winYi+=1
        one+1
        if winJa==3 or winYi==3:
            break
    return winJa,winYi

#模拟
def jichang(n,numA,numB):
    winJa,winYi=0,0
    for _ in range(n):
        winJa,winYi=oneJu(numA,numB)
        if winJa>winYi:
            winJa+=1
        else:
            winYi+=1
    return winJa,winYi

#打印比赛结果
def printBiSaiEnd(chang,winJa,winYi):
    print("比赛结束,共模拟{}场比赛".format(chang))
    print("甲队获取{}场比赛,占比{:0.1%}".format(winJa,winJa/chang))
    print("乙队获取{}场比赛,占比{:0.1%}".format(winYi,winYi/chang))


#编排调用顺序
def main():
    numA,numB,chang =getNengli()
    winJa,winYi=jichang(chang,numA,numB)
    printBiSaiEnd(chang,winJa,winYi)
main()

